package com.auto.api.core.util;

import cn.torna.sdk.common.Booleans;
import cn.torna.sdk.param.DocParamReq;
import cn.torna.sdk.param.DocParamResp;
import com.auto.api.common.utils.JsonMapper;
import com.auto.api.core.constants.MappingConstants;
import com.auto.api.core.entity.BeanMargeContext;
import com.auto.api.core.entity.ClassToMapContext;
import com.auto.api.core.entity.ClassToTornaContext;
import com.auto.api.core.entity.ParamNameResolvableType;
import com.auto.api.core.type.ParseBeanHandler;
import com.auto.api.core.type.TypeFactory;
import com.auto.api.core.type.TypeResultJsonRegister;
import com.auto.api.core.type.defaultvalue.ListTypeHandler;
import com.auto.api.core.type.defaultvalue.ValueTypeHandler;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import io.swagger.annotations.ApiModelProperty;
import java.beans.PropertyDescriptor;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.ResolvableType;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * Description: classUtil
 *
 * @author liangshf
 * @date 2019-06-21
 */
public class BeanUtil {
    public static final Logger logger = LoggerFactory.getLogger(BeanUtil.class);

    public static Map<String, Object> getParamJson(String attr, ResolvableType resolvableType){
        Map<String, Object> newMap = Maps.newHashMap();
        ValueTypeHandler typeHandler = TypeFactory.getTypeHandler(resolvableType.resolve().getSimpleName());
        if (typeHandler != null) {
            newMap.put(attr, typeHandler.getTypeDefaultValue());
        } else {
            //attrValue 转map 设值 转json
            Map<String, Object> map = BeanUtil.getClassColumnMap(resolvableType);
            //参数是接口
            if (map.containsKey(MappingConstants.IS_INTERFACE)) {
                newMap.put(attr, resolvableType.resolve().getName());
            } else {
                for (String key : map.keySet()) {
                    Object object = map.get(key);
                    if (object instanceof Map) {
                        Map<String, Object> newOneMap = Maps.newHashMap();
                        Map<String, Object> leMap = (Map<String, Object>) object;
                        for (String leKey : leMap.keySet()) {
                            Object o = leMap.get(leKey);
                            newOneMap.put(leKey, o);
                        }
                        newMap.put(key, newOneMap);
                    } else {
                        newMap.put(key, object);
                    }
                }
            }
        }
        return newMap;
    }

    public static String getParamsApiJson(List<ParamNameResolvableType> paramResolvableTypeList){
        Map data = getProperties("object", "数据");
        Map dataProperties = Maps.newHashMap();
        for (ParamNameResolvableType paramNameResolvableType : paramResolvableTypeList) {
            getDataProperties(data, dataProperties, paramNameResolvableType);
        }
        return JsonMapper.toJson(data);
    }

    public static String getTornaParamsApiJson(Method method, List<ParamNameResolvableType> paramResolvableTypeList){
        Annotation[][] annotations = method.getParameterAnnotations();
        /** Query参数 */
        List<DocParamReq> queryParams = Lists.newArrayList();
        for (int i =0; i < paramResolvableTypeList.size(); i++) {
            ParamNameResolvableType param = paramResolvableTypeList.get(i);
            getDocParamReqList(queryParams, param);
            if (annotations == null || annotations[i] == null || annotations[i].length == 0) {
                continue;
            }
            Annotation annotation = annotations[i][0];
            if (RequestParam.class.isAssignableFrom(annotation.annotationType())) {
                RequestParam requestParam = (RequestParam)annotation;
                DocParamReq req = queryParams.get(queryParams.size() - 1);
                req.setRequired(requestParam.required() ? Booleans.TRUE : Booleans.FALSE);
            }
        }
        return JsonMapper.toJson(queryParams);
    }

    public static String postTornaParamsApiJson(List<ParamNameResolvableType> paramResolvableTypeList){
        /** POST参数 */
        List<DocParamResp> queryParams = Lists.newArrayList();
        for (ParamNameResolvableType paramNameResolvableType : paramResolvableTypeList) {
            postDocParamRespList(queryParams, paramNameResolvableType);
        }
        return JsonMapper.toJson(queryParams);
    }

    /**
     * 组装返回结果torna api json 字符串
     */
    public static String getTornaApiResultJson(ResolvableType resolvableType){
        if (Objects.isNull(resolvableType)) {
            return "";
        }
        return TypeResultJsonRegister.jsonTypeHandler.getTornaApiResultJson(resolvableType);
    }

    private static void getDocParamReqList(List<DocParamReq> queryParams, ParamNameResolvableType paramNameResolvableType){
        ValueTypeHandler typeHandler = TypeFactory.getTypeHandler(paramNameResolvableType.getParamType().resolve().getSimpleName());
        if (typeHandler == null) {
            //attrValue 转map 设值 转json
            Map<String, Object> map = BeanUtil.getResultApiMap(paramNameResolvableType.getParamType());
            map.forEach((key, value) -> {
                Map object = (Map)value;
                DocParamReq queryCreateParamReq = getDocParamReq(key, object.getOrDefault("type","").toString());
                queryCreateParamReq.setDescription(object.getOrDefault("description","").toString());
                queryParams.add(queryCreateParamReq);
            });
        } else if (typeHandler instanceof ListTypeHandler){
            getTornaListField(null, queryParams, paramNameResolvableType.getParamName());
        } else {
            DocParamReq queryCreateParamReq = getDocParamReq(paramNameResolvableType.getParamType().resolve().getSimpleName(), paramNameResolvableType.getParamName());
            queryParams.add(queryCreateParamReq);
        }
    }

    private static void postDocParamRespList(List<DocParamResp> queryParams, ParamNameResolvableType paramNameResolvableType){
        ValueTypeHandler typeHandler = TypeFactory.getTypeHandler(paramNameResolvableType.getParamType().resolve().getSimpleName());
        if (typeHandler == null) {
            //attrValue 转map 设值 转json
            List<DocParamResp> respList = BeanUtil.getTornaResultApi(paramNameResolvableType.getParamType());
            queryParams.addAll(respList);
        } else if (typeHandler instanceof ListTypeHandler){
            getTornaPostListField(null, queryParams, paramNameResolvableType.getParamName());
        } else {
            DocParamResp queryCreateParamReq = getDocParamResp(paramNameResolvableType.getParamType().resolve().getSimpleName(), paramNameResolvableType.getParamName());
            queryParams.add(queryCreateParamReq);
        }
    }

    private static DocParamResp getDocParamResp(String type, String name) {
        /* 设置Query参数 */
        DocParamResp queryCreateParamReq = new DocParamResp();
        queryCreateParamReq.setName(name);
        queryCreateParamReq.setType(getType(type));
        queryCreateParamReq.setDescription(MappingConstants.EMPTY_STRING);
        queryCreateParamReq.setExample(MappingConstants.EMPTY_STRING);
        queryCreateParamReq.setMaxLength(MappingConstants.EMPTY_STRING);
        queryCreateParamReq.setRequired(Booleans.FALSE);
        queryCreateParamReq.setParentId(MappingConstants.EMPTY_STRING);
        return queryCreateParamReq;
    }

    private static DocParamResp getDocParamRespExample(String type, String name, String example) {
        /* 设置Query参数 */
        DocParamResp queryCreateParamReq = new DocParamResp();
        queryCreateParamReq.setName(name);
        queryCreateParamReq.setType(getType(type));
        queryCreateParamReq.setDescription(MappingConstants.EMPTY_STRING);
        queryCreateParamReq.setExample(example);
        queryCreateParamReq.setMaxLength(MappingConstants.EMPTY_STRING);
        queryCreateParamReq.setRequired(Booleans.FALSE);
        queryCreateParamReq.setParentId(MappingConstants.EMPTY_STRING);
        return queryCreateParamReq;
    }


    private static DocParamReq getDocParamReq(String type, String name) {
        /* 设置Query参数 */
        DocParamReq queryCreateParamReq = new DocParamReq();
        queryCreateParamReq.setName(name);
        queryCreateParamReq.setType(getType(type));
        queryCreateParamReq.setDescription(MappingConstants.EMPTY_STRING);
        queryCreateParamReq.setExample(MappingConstants.EMPTY_STRING);
        queryCreateParamReq.setMaxLength(MappingConstants.EMPTY_STRING);
        queryCreateParamReq.setRequired(Booleans.FALSE);
        queryCreateParamReq.setParentId(MappingConstants.EMPTY_STRING);
        return queryCreateParamReq;
    }

    public static DocParamResp getDocResponseResp(String type, String name) {
        return getDocResponseResp(type, name,"结果对象");
    }

    public static DocParamResp getDocResponseResp(String type, String name, String description) {
        /* 设置返回参数 */
        DocParamResp items = new DocParamResp();
        // id参数
        items.setName(name);
        items.setType(type);
        items.setDescription(description);
        items.setExample(MappingConstants.EMPTY_STRING);
        items.setParentId(MappingConstants.EMPTY_STRING);
        return items;
    }

    private static void getDataProperties(Map data, Map dataProperties, ParamNameResolvableType paramNameResolvableType){
        String simpleParamType = paramNameResolvableType.getParamType().resolve().getSimpleName();
        ValueTypeHandler typeHandler = TypeFactory.getTypeHandler(simpleParamType);
        if (typeHandler == null) {
            //attrValue 转map 设值 转json
            Map<String, Object> map = BeanUtil.getResultApiMap(paramNameResolvableType.getParamType());
            //参数是接口
            if (map.containsKey(MappingConstants.IS_INTERFACE)) {
                dataProperties.put(paramNameResolvableType.getParamName(), getProperties(simpleParamType, MappingConstants.EMPTY_STRING));
            } else {
                dataProperties.putAll(map);
            }
        } else if (typeHandler instanceof ListTypeHandler){
            Map<String, Object> entityColumnMap = Maps.newHashMap();
            getListField(null, entityColumnMap, paramNameResolvableType.getParamName());
            dataProperties.putAll(entityColumnMap);
        } else {
            dataProperties.put(paramNameResolvableType.getParamName(), getProperties(simpleParamType, MappingConstants.EMPTY_STRING));
        }
        data.put("properties", dataProperties);
    }

    public static Map<String, Object> getParamType(String attr, ResolvableType resolvableType){

        Map<String, Object> paramMap = Maps.newHashMap();
        if (TypeFactory.getTypeHandler(resolvableType.resolve().getSimpleName()) != null) {
            paramMap.put(attr, resolvableType.resolve().getSimpleName());
        } else {
            Map<String, Object> map = BeanUtil.getClassColumnTypeMap(resolvableType);
            if (map.containsKey(MappingConstants.IS_INTERFACE)) {
                paramMap.put(attr, MappingConstants.IS_INTERFACE);
            } else {
                paramMap.putAll(map);
            }
        }
        return paramMap;
    }

    public static Map<String, Object> getAutoParamType(String attr, ResolvableType resolvableType){
        Map<String, Object> paramMap = Maps.newHashMap();
        ValueTypeHandler typeHandler = TypeFactory.getTypeHandler(resolvableType.resolve().getSimpleName());
        if (typeHandler != null) {
            paramMap.put(attr, typeHandler.getTypeDefaultValue());
        } else {
            return BeanUtil.getParamColumnMap(resolvableType);
        }
        return paramMap;
    }

    public static String getResultJson(ResolvableType resolvableType){
        if (Objects.isNull(resolvableType)) {
            return "";
        }
        return TypeResultJsonRegister.jsonTypeHandler.getJson(resolvableType);
    }

    /**
     * 组装返回结果api json 字符串
     */
    public static String getApiResultJson(ResolvableType resolvableType){
        if (Objects.isNull(resolvableType)) {
            return "";
        }
        return TypeResultJsonRegister.jsonTypeHandler.getApiResultJson(resolvableType);
    }
    public static Map<String, Object> getClassColumnMap(ResolvableType resolvableType){
        if (Objects.isNull(resolvableType)) {
            return Maps.newHashMap();
        }
        if (resolvableType.resolve().isInterface()) {
            Map<String, Object> resultMap = Maps.newHashMap();
            resultMap.put(MappingConstants.IS_INTERFACE, resolvableType.resolve().getSimpleName());
            return resultMap;
        }
        return buildResultMap(resolvableType, TypeFactory.CLASS_TO_RESULT_COLUMN_MAP);
    }

    public static Map<String, Object> getResultApiMap(ResolvableType resolvableType) {
        return buildResultMap(resolvableType, TypeFactory.CLASS_TO_RESULT_API_MAP);
    }

    public static List<DocParamResp> getTornaResultApi(ResolvableType resolvableType) {
        return buildTornaApiResult(resolvableType, TypeFactory.CLASS_TO_TORNA_RESULT_API_MAP);
    }


    /**
     * 将字符串的首字母转大写
     *
     * @param str 需要转换的字符串
     */
    public static String captureName(String str) {
        // 进行字母的ascii编码前移，效率要高于截取字符串进行转换的操作
        char[] cs = str.toCharArray();
        cs[0] -= 32;
        return String.valueOf(cs);
    }

    public static Map<String, Object> buildResultMap(ResolvableType resolvableType, String buildType){
        ParseBeanHandler<ClassToMapContext, Map<String, Object>> parseBeanHandler = TypeFactory.getParseBeanHandler(buildType);
        return parseBeanHandler.getResult(new ClassToMapContext(resolvableType, MappingConstants.EMPTY_STRING));
    }

    public static List<DocParamResp> buildTornaApiResult(ResolvableType resolvableType, String buildType){
        ParseBeanHandler<ClassToTornaContext, List<DocParamResp>> parseBeanHandler = TypeFactory.getParseBeanHandler(buildType);
        return parseBeanHandler.getResult(new ClassToTornaContext(resolvableType, MappingConstants.EMPTY_STRING));
    }

    /**
     * 根据bean中margeKey注解,将复杂marge 结果集对象合并到result 结果集对象
     * @param result 结果集Bean
     * @param marge 需要合并的Bean
     */
    public static void margeBean(Object result, Object marge) {
        ParseBeanHandler<BeanMargeContext, Object> parseBeanHandler = TypeFactory.getParseBeanHandler(TypeFactory.BEAN_MARGE);
        parseBeanHandler.getResult(new BeanMargeContext(result, marge));
    }

    /**
     * 根据bean中margeKey注解,将复杂marge 结果集对象合并到result 结果集对象
     * @param result 结果集Bean
     * @param marges 需要合并的Bean集合
     */
    public static void margeBeans(Object result, Object ... marges) {
        ParseBeanHandler<BeanMargeContext, Object> parseBeanHandler = TypeFactory.getParseBeanHandler(TypeFactory.BEAN_MARGE);
        for (Object marge : marges) {
            parseBeanHandler.getResult(new BeanMargeContext(result, marge));
        }
    }

    public static void getFiledApi(Class clazz, Map<String, Object> entityColumnMap, PropertyDescriptor prop){
        if (clazz != null) {
            Field field = getField(clazz, prop.getName());
            ApiModelProperty apiModelProperty = field.getAnnotation(ApiModelProperty.class);
            entityColumnMap.put(prop.getName(), getProperties(prop.getPropertyType().getSimpleName(),
                apiModelProperty == null ? MappingConstants.EMPTY_STRING : apiModelProperty.value()));
            NotEmpty notEmpty = field.getAnnotation(NotEmpty.class);
            NotNull notNull = field.getAnnotation(NotNull.class);
            if (notEmpty != null || notNull != null) {
                ((Map)entityColumnMap.get(prop.getName())).put("required", 1);
            }
        } else {
            entityColumnMap.put(prop.getName(), getProperties("string", MappingConstants.EMPTY_STRING));
        }
    }

    public static void getFiledTornaApi(Class clazz, List<DocParamResp> queryParams, PropertyDescriptor prop){
        if (clazz != null) {
            Field field = getField(clazz, prop.getName());
            ApiModelProperty apiModelProperty = field.getAnnotation(ApiModelProperty.class);
            DocParamResp queryCreateParamReq = getDocResponseResp(getType(prop.getPropertyType().getSimpleName()), prop.getName());
            queryCreateParamReq.setDescription(apiModelProperty == null ? MappingConstants.EMPTY_STRING : apiModelProperty.value());
            NotEmpty notEmpty = field.getAnnotation(NotEmpty.class);
            NotNull notNull = field.getAnnotation(NotNull.class);
            if (notEmpty != null || notNull != null) {
                queryCreateParamReq.setRequired(Booleans.TRUE);
            }
            queryParams.add(queryCreateParamReq);
        } else {
            DocParamResp queryCreateParamReq = getDocResponseResp("string", prop.getName());
            queryParams.add(queryCreateParamReq);
        }
    }

    public static void getListField(Class clazz, Map<String, Object> entityColumnMap, String propertyName){
        if (clazz != null) {
            Field field = getField(clazz, propertyName);
            ApiModelProperty apiModelProperty = field.getAnnotation(ApiModelProperty.class);
            Map list = getProperties("array", apiModelProperty == null ? MappingConstants.EMPTY_STRING : apiModelProperty.value());
            Map items = getProperties("string", MappingConstants.EMPTY_STRING);
            list.put("items", items);
            entityColumnMap.put(propertyName, list);
        } else {
            Map list = getProperties("array", MappingConstants.EMPTY_STRING);
            Map items = getProperties("string", MappingConstants.EMPTY_STRING);
            list.put("items", items);
            entityColumnMap.put(propertyName, list);
        }
    }

    public static void getTornaPostListField(Class clazz, List<DocParamResp> queryParams, String propertyName){
        if (clazz != null) {
            Field field = getField(clazz, propertyName);
            ApiModelProperty apiModelProperty = field.getAnnotation(ApiModelProperty.class);
            DocParamResp queryCreateParamReq = getDocParamRespExample("array", propertyName, "[1]");
            queryCreateParamReq.setDescription(apiModelProperty == null ? MappingConstants.EMPTY_STRING : apiModelProperty.value());
            NotEmpty notEmpty = field.getAnnotation(NotEmpty.class);
            NotNull notNull = field.getAnnotation(NotNull.class);
            if (notEmpty != null || notNull != null) {
                queryCreateParamReq.setRequired(Booleans.TRUE);
            }
            queryParams.add(queryCreateParamReq);
        } else {
            DocParamResp queryCreateParamReq = getDocParamRespExample("array", propertyName,"[1]");
            queryParams.add(queryCreateParamReq);
        }
    }

    public static void getTornaSimpleListField(List<DocParamResp> queryParams, String typeName){
        DocParamResp queryCreateParamReq = getDocParamResp("array", MappingConstants.EMPTY_STRING);
        queryCreateParamReq.setChildren(Arrays.asList(getDocParamResp(typeName, MappingConstants.EMPTY_STRING)));
        queryParams.add(queryCreateParamReq);
    }

    public static DocParamResp createTornaListField(){
        DocParamResp queryCreateParamReq = getDocParamResp("array", "");
        return queryCreateParamReq;
    }

    public static void getTornaListField(Class clazz, List<DocParamReq> queryParams, String propertyName){
        if (clazz != null) {
            Field field = getField(clazz, propertyName);
            ApiModelProperty apiModelProperty = field.getAnnotation(ApiModelProperty.class);
            DocParamReq queryCreateParamReq = getDocParamReq("array", propertyName);
            queryCreateParamReq.setChildren(Arrays.asList(getDocParamReq("string", apiModelProperty == null ? "item" : apiModelProperty.value())));
            queryParams.add(queryCreateParamReq);
        } else {
            DocParamReq queryCreateParamReq = getDocParamReq("array", propertyName);
            queryCreateParamReq.setChildren(Arrays.asList(getDocParamReq("string", "item")));
            queryParams.add(queryCreateParamReq);
        }
    }

    public static Field getField(Class clazz, String propertyName){
        List<Field> fieldList = FieldUtils.getAllFieldsList(clazz);
        Map<String, List<Field>> fieldMap = fieldList.stream().filter(f -> !f.getName().equals(MappingConstants.SERIAL_VERSION_UID))
            .collect(Collectors.groupingBy(Field::getName));
        List<Field> oneFieldList = fieldMap.get(propertyName);
        if (oneFieldList == null) {//单个小写字母开头的属性找不到(pCompanyName)
            oneFieldList = fieldMap.get(StringUtils.uncapitalize(propertyName));
        }
        if (oneFieldList == null) {//大写字母开头的属性找不到(Id)
            oneFieldList = fieldMap.get(captureName(propertyName));
        }
        if (oneFieldList == null) {//is开头的属性找不到
            oneFieldList = fieldMap.get("is" + captureName(propertyName));
        }
        if (oneFieldList == null) {
            throw new RuntimeException(String.format("field is null :%s---%s", propertyName, clazz.getSimpleName()));
        }
        return oneFieldList.get(0);
    }

    public static String getType(String type) {
        if (type != null) {
            type = type.toLowerCase();
            type = type.equals("long") ? "string" : type;
        }
        return type;
    }

    public static Map getProperties(String type, String description) {
        Map properties = new HashMap();
        if (type != null) {
            type = type.toLowerCase();
            type = type.equals("long") ? "string" : type;
        }
        properties.put("type", type);
        properties.put("description", description == null ? MappingConstants.EMPTY_STRING : description);
        return properties;
    }

    /**
     * yapi 集合对象返回结果
     * @param clazz
     * @param prop
     * @param columnMap
     * @return
     */
    public static Map getApiJsonArray(Class clazz, PropertyDescriptor prop, Map<String, Object> columnMap) {
        Field field = BeanUtil.getField(clazz, prop.getName());
        ApiModelProperty apiModelProperty = field.getAnnotation(ApiModelProperty.class);
        Map list = BeanUtil.getProperties("array", apiModelProperty == null ? MappingConstants.EMPTY_STRING : apiModelProperty.value());
        Map items = BeanUtil.getProperties("object", "结果对象");
        items.put("properties", columnMap);
        list.put("items", items);
        return list;
    }

    /**
     * yapi object对象返回结果
     * @param clazz
     * @param prop
     * @param columnMap
     * @return
     */
    public static Map getObjApi(Class clazz, PropertyDescriptor prop, Map<String, Object> columnMap) {
        Field field = BeanUtil.getField(clazz, prop.getName());
        ApiModelProperty apiModelProperty = field.getAnnotation(ApiModelProperty.class);
        Map resultMap = BeanUtil.getProperties("object",
            apiModelProperty == null ? MappingConstants.EMPTY_STRING : apiModelProperty.value());
        resultMap.put("properties", columnMap);
        return resultMap;
    }

    public static void setObjDescription(Class clazz, PropertyDescriptor prop, DocParamResp queryCreateParamReq) {
        Field field = BeanUtil.getField(clazz, prop.getName());
        ApiModelProperty apiModelProperty = field.getAnnotation(ApiModelProperty.class);
        queryCreateParamReq.setDescription(apiModelProperty == null ? MappingConstants.EMPTY_STRING : apiModelProperty.value());
    }

    public static Map<String, Object> getClassColumnTypeMap(ResolvableType resolvableType) {
        if (Objects.isNull(resolvableType)) {
            return Maps.newHashMap();
        }
        if (resolvableType.resolve().isInterface()) {
            Map<String, Object> resultMap = Maps.newHashMap();
            resultMap.put(MappingConstants.IS_INTERFACE, MappingConstants.IS_INTERFACE);
            return resultMap;
        }
        return buildResultMap(resolvableType, TypeFactory.CLASS_TO_COLUMN_TYPE_MAP);
    }

    /**
     * 获取参数 className 对应属性map
     */
    public static Map<String, Object> getParamColumnMap(ResolvableType resolvableType){
        if (Objects.isNull(resolvableType)) {
            return Maps.newHashMap();
        }
        if (resolvableType.resolve().isInterface()) {
            Map<String, Object> resultMap = Maps.newHashMap();
            resultMap.put(MappingConstants.IS_INTERFACE, MappingConstants.IS_INTERFACE);
            return resultMap;
        }
        return buildResultMap(resolvableType, TypeFactory.CLASS_TO_PARAM_COLUMN_MAP);
    }

    /**
     * 获取参数 className 对应属性map
     */
    public static Class getClass(String className){
        if (className.equals("?")) {
            logger.info("className is isInterface:{}", className);
            return null;
        }
        try {
            Class clazz = Class.forName(className);
            //静态内部类
            if (className.indexOf(MappingConstants.INNER_CLASS_SEPARATOR) != -1) {
                return clazz;
            }
            if (clazz.isInterface()) {
                logger.info("className is isInterface:{}", className);
                return null;
            }
            return clazz;
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e.getMessage());
        }
    }

}
